// 根据角色动态生成路由
import { MockMethod } from "vite-plugin-mock";

export default [
  {
    url: "/api/user/login",
    method: "post",
    response: ({ body }) => {
      return {
        code: 2000,
        message: "操作成功",
        data: {
          username: "common",
          // 一个用户可能有多个角色
          roles: ["common"],
          accessToken: "eyJhbGciOiJIUzUxMiJ9.common",
          refreshToken: "eyJhbGciOiJIUzUxMiJ9.commonRefresh",
          expires: "2023/10/30 00:00:00"
        }
      };

      if (body.username === "admin") {
        return {
          success: true,
          data: {
            username: "admin",
            // 一个用户可能有多个角色
            roles: ["admin"],
            accessToken: "eyJhbGciOiJIUzUxMiJ9.admin",
            refreshToken: "eyJhbGciOiJIUzUxMiJ9.adminRefresh",
            expires: "2023/10/30 00:00:00",
            test: "test"
          }
        };
      } else {
        return {
          success: true,
          data: {
            username: "common",
            // 一个用户可能有多个角色
            roles: ["common"],
            accessToken: "eyJhbGciOiJIUzUxMiJ9.common",
            refreshToken: "eyJhbGciOiJIUzUxMiJ9.commonRefresh",
            expires: "2023/10/30 00:00:00"
          }
        };
      }
    }
  },
  {
    url: "/api/user/logout",
    method: "get",
    response: ({ body }) => {
      return {
        message: "操作成功",
        code: 2000,
        data: {}
      };
    }
  },
  {
    url: "/api/user/getVerifyCode",
    method: "get",
    response: ({ body }) => {
      return {
        success: true,
        data: {
          verImgUrl: "/assets/img.png",
          verImgCode: "9067"
        }
      };
    }
  }
] as MockMethod[];
